package de.stefanocke.roo.wicket.base;

import org.springframework.roo.project.LogicalPath;
import org.springframework.roo.project.Path;

import de.stefanocke.roo.wicket.MidUtils;

public abstract class PathUtil {
	/**
	 * Gets the relativ filename for the given java type. The suffix ".java" is repalced by the given suffix to 
	 * allow to create property or html files that have the same name and package as the java type.
	 * @param mid the metadata id 
	 * @param suffix the requested suffix. For example "properties"
	 * @return the relative filename. For example com/example/Foo.properties
	 */
	public static String getRelativeFilename(String mid, String suffix) {
		MidUtils midUtils = MidUtils.getForMid(mid);		
		
		//f.e. "com/example/Foo.java"
		String relativeFilename = midUtils.getJavaType(mid).getRelativeFileName() ;
		
		// cut off "java" and append new suffix
		
		relativeFilename = relativeFilename.substring(0, relativeFilename.length() - 4) + suffix;
		return relativeFilename;
	}

	/**
	 * Gets the src/main/resources path in the module where the given metadata item lives.
	 * @param mid the metadata id
	 * @return the logical path for src/main/resources 
	 */
	public static LogicalPath getResourcesPath(String mid) {
		MidUtils midUtils = MidUtils.getForMid(mid);
		LogicalPath javaPath = midUtils.getPath(mid);		
		LogicalPath logicalPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, javaPath.getModule());
		return logicalPath;
	}
	
	public static void main(String[] args){
		getRelativeFilename("MID:de.stefanocke.roo.wicket.table.TableMetadata#SRC_MAIN_JAVA?de.saxsys.wicket.blog.web.post.PostTable", "properties");
	}
}
